home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MAIL.SWG / 0018_Numbers in QWK packets.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  2KB  |  84 lines

  1. {
  2. TH> Apparently this contains the filepositions of the records (and also the
  3. TH> conference numbers?) but the numbers are not in normal format. Can somebody
  4. TH>  please explain the format of this file and how to convert these numbers to
  5. TH> and from something TP can work with?
  6.  
  7. There is supposed to be at least two doc's explaining the QWK format. I have
  8. here a unit that converts the integer to basicreal (i guess it's what you
  9. need..) I'm sorry I can't remember the of the doc's..
  10.  
  11. ------------------- 8<
  12. }
  13. Unit BasConv;
  14.  
  15. Interface
  16.   Function BasicReal2Long(InValue: LongInt): LongInt;
  17.                 {Convert Basic Short Reals to LongInts}
  18.  
  19.   Function Long2BasicReal(InValue: LongInt): LongInt;
  20.                 {Convert LongInts to Basic Short Reals}
  21.  
  22. Implementation
  23.  
  24. Function BasicReal2Long(InValue: LongInt): LongInt;
  25.  
  26.   Var
  27.   Temp: LongInt;
  28.   Expon: Integer;
  29.  
  30.   Begin
  31.   Expon := ((InValue shr 24) and $ff) - 152;
  32.   Temp := (InValue and $007FFFFF) or $00800000;
  33.   If Expon < 0 Then
  34.     Temp := Temp shr Abs(Expon)
  35.   Else
  36.     Temp := Temp shl Expon;
  37.   If (InValue and $00800000) <> 0 Then
  38.     BasicReal2Long := -Temp
  39.   Else
  40.     BasicReal2Long := Temp;
  41.   If Expon = 0 Then
  42.     BasicReal2Long := 0;
  43.   End;
  44.  
  45.  
  46. Function Long2BasicReal(InValue: LongInt): LongInt;
  47.   Var
  48.   Negative: Boolean;
  49.   Expon: LongInt;
  50.  
  51.   Begin
  52.   If InValue = 0 Then
  53.     Long2BasicReal := 0
  54.   Else
  55.     Begin
  56.     If InValue < 0 Then
  57.       Begin
  58.       Negative := True;
  59.       InValue := Abs(InValue);
  60.       End
  61.     Else
  62.       Negative := False;
  63.     Expon := 152;
  64.     If InValue < $007FFFFF Then
  65.       While ((InValue and $00800000) = 0) Do
  66.         Begin
  67.         InValue := InValue shl 1;
  68.         Dec(Expon);
  69.         End
  70.     Else
  71.       While ((InValue And $FF000000) <> 0) Do
  72.         Begin
  73.         InValue := InValue shr 1;
  74.         Inc(Expon);
  75.         End;
  76.     InValue := InValue And $007FFFFF;
  77.     If Negative Then
  78.       InValue := InValue Or $00800000;
  79.     Long2BasicReal := InValue + (Expon shl 24);
  80.     End;
  81.   End;
  82.  
  83. End.
  84.